const curry = (fn) => {
    let params = []
    const curried = (...args) => {
        if(args.length <= 0) {
            const allParams = params;
            params = [];
            return fn(...allParams)
        }

        params = [...params,...args]
        return curried
    }
    return curried
}

//案例1
function add(...args) {
    const result = args.reduce((a, b) => {
        return a + b
    })
}

add(1, 2, 3)
const currAdd = curry(add)
currAdd(1)(2)(3)()
currAdd(1, 2)(3)()
currAdd(1)(2, 3)()

//案例2
function logger(...args) {
    let content = '';
    for (let i = 0; i < args.length; i++) {
        content = `${content}${args[i]}`
    }
}

logger('我', '是', '中国人')

const currLogger = curry(logger)
currLogger('我')('是')('中国人')()
currLogger('我', '是')('中国人')()
currLogger('我')('是', '中国人')()


